<template>
  <div>
    <vxe-toolbar :setting="{immediate:true}">
      <template v-slot:buttons>
        <el-button v-if="$hasPermission('msg:msgBizChannel:save')" type="primary" @click="addOrUpdateHandle()">
          {{ $t('add') }}</el-button>
        <el-button v-if="$hasPermission('msg:msgBizChannel:delete')" type="danger" @click="deleteHandle()">
          {{ $t('deleteBatch') }}</el-button>
      </template>
      <template v-slot:tools>
        <!-- <el-button icon="el-icon-search" @click="searchShowHandle()" circle></el-button> -->
        <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        <!-- <el-button icon="el-icon-download" @click="$refs.xTable.openExport()" circle></el-button> -->
      </template>
    </vxe-toolbar>
    <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex" :data="dataList">
      <vxe-table-column type="checkbox" align="center" width="60"></vxe-table-column>
      <!-- <vxe-table-column field="bizTypeCode" title="业务类型编码" width="300">
        <template slot-scope="scope">
          {{$getDictLabel('MSG_BIZ_TYPE', scope.row.bizTypeCode)}}({{scope.row.bizTypeCode}})
        </template>
      </vxe-table-column> -->
      <vxe-table-column field="channelType" title="通道类型">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.channelType === '0'" size="small">内置通道</el-tag>
          <el-tag v-if="scope.row.channelType === '1'" size="small">自定义通道</el-tag>
        </template>
      </vxe-table-column>
      <vxe-table-column field="channelCode" title="通道编码">
        <template slot-scope="scope">
          {{$getDictLabel('MSG_CHANNEL', scope.row.channelCode)}}
        </template>
      </vxe-table-column>
      <vxe-table-column field="templateId" title="模板编码">
      </vxe-table-column>
      <vxe-table-column field="customClass" title="自定义类名">
      </vxe-table-column>
      <vxe-table-column field="customMethod" title="自定义方法名">
      </vxe-table-column>
      <vxe-table-column title="handle" fixed="right" align="center" width="120">
        <template slot-scope="scope">
          <el-button v-if="$hasPermission('msg:msgBizChannel:update')" type="text" size="small" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}</el-button>
          <el-button v-if="$hasPermission('msg:msgBizChannel:delete')" type="text" size="small" icon="el-icon-delete" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
        </template>
      </vxe-table-column>
    </vxe-table>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './msgBizRule-channel-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        activatedIsNeed: false,
        getDataListURL: '/msg/msgBizChannel/list',
        getDataListIsPage: false,
        deleteURL: '/msg/msgBizChannel',
        deleteIsBatch: true
      },
      dataForm: {
        bizTypeCode: '',
        channelType: '',
        channelCode: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.dataForm.bizTypeCode = this.dataForm.bizTypeCode
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>
